package com.aba.hms.admin;


	import javax.swing.*;
	import java.awt.*;
	import java.awt.event.ActionEvent;
	import java.awt.event.ActionListener;

	public class Admin {
	    private JFrame loginFrame;
	    private JFrame mainFrame;
	    private JTextField usernameField;
	    private JPasswordField passwordField;
	    private JTextField roomNumberField;
	    private JTextField roomTypeField;
	    private JTextField roomPriceField;
	    private JButton loginButton;
	    private JButton logoutButton;
	    private JButton addRoomButton;
	    private JLabel statusLabel;

	    public Admin() {
	        createLoginForm();
	    }

	    private void createLoginForm() {
	        loginFrame = new JFrame("酒店管理系统 - 登录");
	        loginFrame.setSize(300, 200);
	        loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        loginFrame.setLayout(new GridLayout(4, 2));

	        loginFrame.add(new JLabel("用户名:"));
	        usernameField = new JTextField();
	        loginFrame.add(usernameField);

	        loginFrame.add(new JLabel("密码:"));
	        passwordField = new JPasswordField();
	        loginFrame.add(passwordField);

	        loginButton = new JButton("登录");
	        loginButton.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                performLogin();
	            }
	        });
	        loginFrame.add(loginButton);

	        loginFrame.setVisible(true);
	    }

	    private void createMainFrame() {
	        mainFrame = new JFrame("酒店管理系统 - 主界面");
	        mainFrame.setSize(400, 300);
	        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        mainFrame.setLayout(new GridLayout(7, 2));

	        mainFrame.add(new JLabel("客房号:"));
	        roomNumberField = new JTextField();
	        mainFrame.add(roomNumberField);

	        mainFrame.add(new JLabel("客房类型:"));
	        roomTypeField = new JTextField();
	        mainFrame.add(roomTypeField);

	        mainFrame.add(new JLabel("客房价格:"));
	        roomPriceField = new JTextField();
	        mainFrame.add(roomPriceField);

	        addRoomButton = new JButton("新增客房");
	        addRoomButton.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                performAddRoom();
	            }
	        });
	        mainFrame.add(addRoomButton);

	        logoutButton = new JButton("退出登录");
	        logoutButton.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent e) {
	                performLogout();
	            }
	        });
	        mainFrame.add(logoutButton);

	        statusLabel = new JLabel("状态: 已登录");
	        mainFrame.add(statusLabel);

	        mainFrame.setVisible(true);
	    }

	    private void performLogin() {
	        String username = usernameField.getText();
	        String password = new String(passwordField.getPassword());

	        // 简单的登录验证
	        if ("admin".equals(username) && "12345".equals(password)) {
	            loginFrame.setVisible(false);
	            createMainFrame();
	        } else {
	            JOptionPane.showMessageDialog(loginFrame, "用户名或密码错误", "登录失败", JOptionPane.ERROR_MESSAGE);
	        }
	    }

	    private void performLogout() {
	        mainFrame.setVisible(false);
	        loginFrame.setVisible(true);
	    }

	    private void performAddRoom() {
	        String roomNumber = roomNumberField.getText();
	        String roomType = roomTypeField.getText();
	        String roomPrice = roomPriceField.getText();

	        if (roomNumber.isEmpty() || roomType.isEmpty() || roomPrice.isEmpty()) {
	            JOptionPane.showMessageDialog(mainFrame, "请输入完整的客房信息", "新增失败", JOptionPane.ERROR_MESSAGE);
	            return;
	        }

	        // 简单的新增客房操作（这里只是显示提示信息）
	        JOptionPane.showMessageDialog(mainFrame, "客房号: " + roomNumber + "\n客房类型: " + roomType + "\n客房价格: " + roomPrice + "\n新增成功", "新增成功", JOptionPane.INFORMATION_MESSAGE);
	        roomNumberField.setText("");
	        roomTypeField.setText("");
	        roomPriceField.setText("");
	    }

	    public static void main(String[] args) {
	        SwingUtilities.invokeLater(new Runnable() {
	            @Override
	            public void run() {
	                new Admin();
	            }
	        });
	    }
	}
	


